unit simplekeybd;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, Classes, fpg_base, fpg_main, fpg_form, fpg_button, fpg_dialogs, fpg_panel;

type

  { TKeyButton }

  TKeyButton = class(TfpgButton)
  private
    fUpperCaseChar: Char;
    fLowerCaseChar: Char;
  public
    function GetChar(Caps: Boolean): Char;
    procedure SetChars(upper, lower: Char);
  end;

  { TSimpleKeyboard }

  TSimpleKeyboard = class(TfpgForm)
  private
    fLineBuffer: string;
    fOnBufferUpdate: TNotifyEvent;
    fOnDelete: TNotifyEvent;
    fOnReturn: TNotifyEvent;
    {@VFD_HEAD_BEGIN: SimpleKeyboard}
    Button101: TKeyButton;
    Button102: TKeyButton;
    Button103: TKeyButton;
    Button104: TKeyButton;
    Button105: TKeyButton;
    Button106: TKeyButton;
    Button107: TKeyButton;
    Button108: TKeyButton;
    Button109: TKeyButton;
    Button110: TKeyButton;
    Button111: TKeyButton;
    Button112: TKeyButton;
    Button201: TKeyButton;
    Button202: TKeyButton;
    Button203: TKeyButton;
    Button204: TKeyButton;
    Button205: TKeyButton;
    Button206: TKeyButton;
    Button207: TKeyButton;
    Button208: TKeyButton;
    Button209: TKeyButton;
    Button210: TKeyButton;
    Button211: TKeyButton;
    Button212: TKeyButton;
    Button301: TKeyButton;
    Button302: TKeyButton;
    Button303: TKeyButton;
    Button304: TKeyButton;
    Button305: TKeyButton;
    Button306: TKeyButton;
    Button307: TKeyButton;
    Button308: TKeyButton;
    Button309: TKeyButton;
    Button310: TKeyButton;
    Button311: TKeyButton;
    Button312: TKeyButton;
    Button401: TKeyButton;
    Button402: TKeyButton;
    Button403: TKeyButton;
    Button404: TKeyButton;
    Button405: TKeyButton;
    Button406: TKeyButton;
    Button407: TKeyButton;
    Button408: TKeyButton;
    Button409: TKeyButton;
    Button410: TKeyButton;
    Button411: TKeyButton;
    CapsButton: TfpgButton;
    SpaceButton: TfpgButton;
    EnterButton: TfpgButton;
    DelBackButton: TfpgButton;
    CloseButton: TfpgButton;
    Bevel1: TfpgBevel;
    {@VFD_HEAD_END: SimpleKeyboard}
    procedure CapsKeyHit(Sender: TObject);
    procedure CloseKeyHit(Sender: TObject);
    procedure DeleteKeyHit(Sender: TObject);
    procedure KeyHit(Sender: TObject);
  public
    procedure AfterCreate; override;
    property OnBufferUpdate: TNotifyEvent read fOnBufferUpdate write fOnBufferUpdate;
    property OnDelete: TNotifyEvent read fOnDelete write fOnDelete;
    property OnReturn: TNotifyEvent read fOnReturn write fOnReturn;
  end;

{@VFD_NEWFORM_DECL}

var
  ScreenKeyboard: TSimpleKeyboard;


implementation

{ TKeyButton }

function TKeyButton.GetChar(Caps: Boolean): Char;
begin
  if Caps
     then Result := fUpperCaseChar
     else Result := fLowerCaseChar;
end;

procedure TKeyButton.SetChars(upper, lower: Char);
begin
  fUpperCaseChar := upper;
  fLowerCaseChar := lower;
end;

{@VFD_NEWFORM_IMPL}

procedure TSimpleKeyboard.CapsKeyHit(Sender: TObject);
var
  g: TfpgFontSelectDialog;
  fontdesc: string;
begin
  CapsButton.AllowDown := not CapsButton.AllowDown;
  if CapsButton.Down
     then CapsButton.BackgroundColor := clRed
     else CapsButton.BackgroundColor := clButtonFace;
  {g := TfpgFontSelectDialog.Create(nil);
  if g.ShowModal then ShowMessage(g.getfont);
  SelectFontDialog(fontdesc);
  ShowMessage(fontdesc);
  fpgSetNamedFont('#KeyBoard1', fontdesc);
  Button201.FontDesc := fontdesc;       }

end;

procedure TSimpleKeyboard.CloseKeyHit(Sender: TObject);
begin
  Self.Hide;
end;

procedure TSimpleKeyboard.DeleteKeyHit(Sender: TObject);
begin
  if Assigned(fOnDelete)
     then fOnDelete(Sender);
end;

procedure TSimpleKeyboard.KeyHit(Sender: TObject);
begin
  fLineBuffer := fLineBuffer + TKeyButton(Sender).GetChar(CapsButton.Down);
end;

procedure TSimpleKeyboard.AfterCreate;
begin
  {%region 'Auto-generated GUI code' -fold}
  {@VFD_BODY_BEGIN: SimpleKeyboard}
  Name := 'SimpleKeyboard';
  SetPosition(300, 150, 758, 298);
  WindowTitle := 'SimpleKeyboard';
  Hint := '';

  Button101 := TKeyButton.Create(self);
  with Button101 do
  begin
    Name := 'Button101';
    SetPosition(10, 8, 50, 50);
    Text := '1';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button102 := TKeyButton.Create(self);
  with Button102 do
  begin
    Name := 'Button102';
    SetPosition(65, 8, 50, 50);
    Text := '2';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button103 := TKeyButton.Create(self);
  with Button103 do
  begin
    Name := 'Button103';
    SetPosition(120, 8, 50, 50);
    Text := '3';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button104 := TKeyButton.Create(self);
  with Button104 do
  begin
    Name := 'Button104';
    SetPosition(175, 8, 50, 50);
    Text := '4';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button105 := TKeyButton.Create(self);
  with Button105 do
  begin
    Name := 'Button105';
    SetPosition(230, 8, 50, 50);
    Text := '5';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button106 := TKeyButton.Create(self);
  with Button106 do
  begin
    Name := 'Button106';
    SetPosition(285, 8, 50, 50);
    Text := '6';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button107 := TKeyButton.Create(self);
  with Button107 do
  begin
    Name := 'Button107';
    SetPosition(340, 8, 50, 50);
    Text := '7';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button108 := TKeyButton.Create(self);
  with Button108 do
  begin
    Name := 'Button108';
    SetPosition(395, 8, 50, 50);
    Text := '8';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button109 := TKeyButton.Create(self);
  with Button109 do
  begin
    Name := 'Button109';
    SetPosition(450, 8, 50, 50);
    Text := '9';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button110 := TKeyButton.Create(self);
  with Button110 do
  begin
    Name := 'Button110';
    SetPosition(505, 8, 50, 50);
    Text := '0';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button111 := TKeyButton.Create(self);
  with Button111 do
  begin
    Name := 'Button111';
    SetPosition(560, 8, 50, 50);
    Text := '- _';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button112 := TKeyButton.Create(self);
  with Button112 do
  begin
    Name := 'Button112';
    SetPosition(615, 8, 50, 50);
    Text := '= +';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button201 := TKeyButton.Create(self);
  with Button201 do
  begin
    Name := 'Button201';
    SetPosition(14, 76, 50, 50);
    Text := 'Q';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button202 := TKeyButton.Create(self);
  with Button202 do
  begin
    Name := 'Button202';
    SetPosition(69, 76, 50, 50);
    Text := 'W';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button203 := TKeyButton.Create(self);
  with Button203 do
  begin
    Name := 'Button203';
    SetPosition(124, 76, 50, 50);
    Text := 'E';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button204 := TKeyButton.Create(self);
  with Button204 do
  begin
    Name := 'Button204';
    SetPosition(179, 76, 50, 50);
    Text := 'R';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button205 := TKeyButton.Create(self);
  with Button205 do
  begin
    Name := 'Button205';
    SetPosition(234, 76, 50, 50);
    Text := 'T';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button206 := TKeyButton.Create(self);
  with Button206 do
  begin
    Name := 'Button206';
    SetPosition(289, 76, 50, 50);
    Text := 'Y';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button207 := TKeyButton.Create(self);
  with Button207 do
  begin
    Name := 'Button207';
    SetPosition(344, 76, 50, 50);
    Text := 'U';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button208 := TKeyButton.Create(self);
  with Button208 do
  begin
    Name := 'Button208';
    SetPosition(399, 76, 50, 50);
    Text := 'I';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button209 := TKeyButton.Create(self);
  with Button209 do
  begin
    Name := 'Button209';
    SetPosition(454, 76, 50, 50);
    Text := 'O';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button210 := TKeyButton.Create(self);
  with Button210 do
  begin
    Name := 'Button210';
    SetPosition(509, 76, 50, 50);
    Text := 'P';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button211 := TKeyButton.Create(self);
  with Button211 do
  begin
    Name := 'Button211';
    SetPosition(564, 76, 50, 50);
    Text := '[{';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  Button212 := TKeyButton.Create(self);
  with Button212 do
  begin
    Name := 'Button212';
    SetPosition(619, 76, 50, 50);
    Text := ']}';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @KeyHit;
  end;

  CapsButton := TfpgButton.Create(self);
  with CapsButton do
  begin
    Name := 'CapsButton';
    SetPosition(14, 240, 112, 50);
    Text := 'Caps';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 13;
    OnClick := @CapsKeyHit;
    AllowAllUp := true;
    AllowDown := true;
  end;

  Button301 := TKeyButton.Create(self);
  with Button301 do
  begin
    Name := 'Button301';
    SetPosition(35, 130, 50, 50);
    Text := 'A';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 14;
    OnClick := @KeyHit;
  end;

  Button302 := TKeyButton.Create(self);
  with Button302 do
  begin
    Name := 'Button302';
    SetPosition(90, 130, 50, 50);
    Text := 'S';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 14;
    OnClick := @KeyHit;
  end;

  Button303 := TKeyButton.Create(self);
  with Button303 do
  begin
    Name := 'Button303';
    SetPosition(145, 130, 50, 50);
    Text := 'D';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 14;
    OnClick := @KeyHit;
  end;

  Button304 := TKeyButton.Create(self);
  with Button304 do
  begin
    Name := 'Button304';
    SetPosition(200, 130, 50, 50);
    Text := 'F';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 14;
    OnClick := @KeyHit;
  end;

  Button305 := TKeyButton.Create(self);
  with Button305 do
  begin
    Name := 'Button305';
    SetPosition(255, 130, 50, 50);
    Text := 'G';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 14;
    OnClick := @KeyHit;
  end;

  Button306 := TKeyButton.Create(self);
  with Button306 do
  begin
    Name := 'Button306';
    SetPosition(310, 130, 50, 50);
    Text := 'H';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 14;
    OnClick := @KeyHit;
  end;

  Button307 := TKeyButton.Create(self);
  with Button307 do
  begin
    Name := 'Button307';
    SetPosition(365, 130, 50, 50);
    Text := 'J';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 14;
    OnClick := @KeyHit;
  end;

  Button308 := TKeyButton.Create(self);
  with Button308 do
  begin
    Name := 'Button308';
    SetPosition(420, 130, 50, 50);
    Text := 'K';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 14;
    OnClick := @KeyHit;
  end;

  Button309 := TKeyButton.Create(self);
  with Button309 do
  begin
    Name := 'Button309';
    SetPosition(475, 130, 50, 50);
    Text := 'L';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 14;
    OnClick := @KeyHit;
  end;

  Button310 := TKeyButton.Create(self);
  with Button310 do
  begin
    Name := 'Button310';
    SetPosition(530, 130, 50, 50);
    Text := '; :';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 14;
    OnClick := @KeyHit;
  end;

  Button311 := TKeyButton.Create(self);
  with Button311 do
  begin
    Name := 'Button311';
    SetPosition(585, 130, 50, 50);
    Text := ''' @';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 14;
    OnClick := @KeyHit;
  end;

  Button312 := TKeyButton.Create(self);
  with Button312 do
  begin
    Name := 'Button312';
    SetPosition(640, 130, 50, 50);
    Text := '# ~';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 14;
    OnClick := @KeyHit;
  end;

  SpaceButton := TfpgButton.Create(self);
  with SpaceButton do
  begin
    Name := 'SpaceButton';
    SetPosition(200, 240, 348, 50);
    Text := 'Space';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 26;
    OnClick := @KeyHit;
  end;

  Button401 := TKeyButton.Create(self);
  with Button401 do
  begin
    Name := 'Button401';
    SetPosition(15, 185, 50, 50);
    Text := '\ |';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 27;
    OnClick := @KeyHit;
  end;

  Button402 := TKeyButton.Create(self);
  with Button402 do
  begin
    Name := 'Button402';
    SetPosition(70, 185, 50, 50);
    Text := 'Z';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 27;
    OnClick := @KeyHit;
  end;

  Button403 := TKeyButton.Create(self);
  with Button403 do
  begin
    Name := 'Button403';
    SetPosition(125, 185, 50, 50);
    Text := 'X';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 27;
    OnClick := @KeyHit;
  end;

  Button404 := TKeyButton.Create(self);
  with Button404 do
  begin
    Name := 'Button404';
    SetPosition(180, 185, 50, 50);
    Text := 'C';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 27;
    OnClick := @KeyHit;
  end;

  Button405 := TKeyButton.Create(self);
  with Button405 do
  begin
    Name := 'Button405';
    SetPosition(235, 185, 50, 50);
    Text := 'V';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 27;
    OnClick := @KeyHit;
  end;

  Button406 := TKeyButton.Create(self);
  with Button406 do
  begin
    Name := 'Button406';
    SetPosition(290, 185, 50, 50);
    Text := 'B';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 27;
    OnClick := @KeyHit;
  end;

  Button407 := TKeyButton.Create(self);
  with Button407 do
  begin
    Name := 'Button407';
    SetPosition(345, 185, 50, 50);
    Text := 'N';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 27;
    OnClick := @KeyHit;
  end;

  Button408 := TKeyButton.Create(self);
  with Button408 do
  begin
    Name := 'Button408';
    SetPosition(400, 185, 50, 50);
    Text := 'M';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 27;
    OnClick := @KeyHit;
  end;

  Button409 := TKeyButton.Create(self);
  with Button409 do
  begin
    Name := 'Button409';
    SetPosition(455, 185, 50, 50);
    Text := ', <';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 27;
    OnClick := @KeyHit;
  end;

  Button410 := TKeyButton.Create(self);
  with Button410 do
  begin
    Name := 'Button410';
    SetPosition(510, 185, 50, 50);
    Text := '. >';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 27;
    OnClick := @KeyHit;
  end;

  Button411 := TKeyButton.Create(self);
  with Button411 do
  begin
    Name := 'Button411';
    SetPosition(565, 185, 50, 50);
    SetChars('/', '?'); Text := '/';
    FontDesc := '#KeyBoard1';
    Hint := '';
    ImageName := '';
    TabOrder := 27;
    OnClick := @KeyHit;
  end;

  EnterButton := TfpgButton.Create(self);
  with EnterButton do
  begin
    Name := 'EnterButton';
    SetPosition(696, 76, 56, 104);
    Text := 'Return';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 28;
  end;

  DelBackButton := TfpgButton.Create(self);
  with DelBackButton do
  begin
    Name := 'DelBackButton';
    SetPosition(672, 8, 80, 50);
    Text := '<= Delete';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 29;
  end;

  CloseButton := TfpgButton.Create(self);
  with CloseButton do
  begin
    Name := 'CloseButton';
    SetPosition(672, 240, 80, 50);
    Text := 'Close';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 40;
    OnClick := @CloseKeyHit;
  end;

  Bevel1 := TfpgBevel.Create(self);
  with Bevel1 do
  begin
    Name := 'Bevel1';
    SetPosition(10, 64, 740, 4);
    Hint := '';
  end;

  {@VFD_BODY_END: SimpleKeyboard}
  {%endregion}
end;


end.
